using Exploder.Utils;
using UnityEngine;

namespace Exploder.Examples
{
	public class ExplodeAllObjects : MonoBehaviour
	{
		private ExploderObject Exploder;

		private GameObject[] DestroyableObjects;

		private int counter;

		private void Start()
		{
			DestroyableObjects = GameObject.FindGameObjectsWithTag("Exploder");
			Exploder = ExploderSingleton.ExploderInstance;
		}

		private void Update()
		{
			if (UnityEngine.Input.GetKeyDown(KeyCode.Return))
			{
				GameObject[] destroyableObjects = DestroyableObjects;
				foreach (GameObject gameObject in destroyableObjects)
				{
					ExplodeObject(gameObject);
				}
			}
		}

		private void ExplodeObject(GameObject gameObject)
		{
			ExploderUtils.SetActive(Exploder.gameObject, status: true);
			Exploder.transform.position = ExploderUtils.GetCentroid(gameObject);
			Exploder.Radius = 1f;
			Exploder.ExplodeRadius();
		}

		private void OnGUI()
		{
			GUI.Label(new Rect(200f, 10f, 300f, 30f), "Hit enter to explode everything!");
		}
	}
}
